const log4js = require('log4js')
// const data = new Date()

log4js.configure({
    // appenders: {
    //     everything: { type: 'file', filename: `logs/${new Date().toLocaleDateString()}.log` }
    // },
    // categories: {
    //     default: { appenders: [ 'everything' ], level: 'info' }
    // }
    replaceConsole: true,
    appenders: {
        stdout: {//控制台输出
            type: 'stdout'
        },
        req: {//请求日志
            type: 'dateFile',
            filename: 'logs/reqlog/',
            pattern: 'req-yyyy-MM-dd.log',
            alwaysIncludePattern: true
        },
        err: {//错误日志
            type: 'dateFile',
            filename: 'logs/errlog/',
            pattern: 'err-yyyy-MM-dd.log',
            alwaysIncludePattern: true
        },
        oth: {//其他日志
            type: 'dateFile',
            filename: 'logs/othlog/',
            pattern: 'oth-yyyy-MM-dd.log',
            alwaysIncludePattern: true
        }
    },
    categories: {
        default: { appenders: ['stdout', 'req'], level: 'debug' },//appenders:采用的appender,取appenders项,level:设置级别
        err: { appenders: ['stdout', 'err'], level: 'error' },
        oth: { appenders: ['stdout', 'oth'], level: 'info' }
    }
})

const logger = log4js.getLogger() // logger.info()
const errlogger = log4js.getLogger('err')
const othlogger = log4js.getLogger('oth')

exports.logger = logger
exports.errlogger = errlogger
exports.othlogger = othlogger